package com.yonyou.pmclouds.plan.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.basecom.view.DisableWrap;
import com.yonyou.pmclouds.plan.plandriven.entity.InvokeResultVO;
import com.yonyou.pmclouds.plan.plandriven.entity.PlanDrivenParamVO;
import com.yonyou.pmclouds.plan.plandriven.rmiitf.IScheduleDriven;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 里程碑单据驱动计划，供NC调用
 *
 * @author th
 * @date 2019/11/22 16:49
 */
@RestController
@RequestMapping("/outter/planDriven")
public class ScheduleDrivenController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private IScheduleDriven scheduleDriven;

    @RequestMapping("/drive")
    @DisableWrap
    public InvokeResultVO drivePlan(@RequestBody PlanDrivenParamVO paramVO, HttpServletRequest request) throws BusinessException {
        // 外系统调用不会走过滤器，由于在实现类中会用到租户，所以从header获取租户设置到线程中，
        String tenantId = request.getHeader("accountId");
        RuntimeEnvironment.setTenantId(tenantId);
        return scheduleDriven.drivePlanByMilestoneBill(paramVO);
    }

    @RequestMapping("/sendMessageManually")
    @DisableWrap
    public InvokeResultVO sendMessageManually(@RequestBody String[] planIds) throws BusinessException {
        return scheduleDriven.sendMessageManually(planIds);
    }

}
